/*
 * Socket.h
 *
 *  Created on: 2010-6-22
 *      Author: guobc
 */

#ifndef SOCKET_H_
#define SOCKET_H_

#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>

namespace HA {
class Socket {
public:

	Socket() :
		m_rfds(), m_wfds() {
	}

	void socketConnect(const char* domain, int port);

	void socketSend(const char* fmt, ...);

	void socketAdd();

	void socketRead(char* buffer, int len);

	void downloadContents(const char* tempName);

	inline void socketClose() {
		close(m_socket) < 0 ? m_good = false : m_good = true;
	}

	inline int getSocket() {
		return m_socket;
	}

	inline bool good() const {
		return m_good;
	}

private:
	int m_socket;
	int m_maxsocket;
	bool m_good;
	fd_set m_rfds;
	fd_set m_wfds;
};
}

#endif /* SOCKET_H_ */
